package com.kingsoft.dc.khaos.extender.meta.impl;

import com.alibaba.fastjson.JSON;
import com.kingsoft.dc.khaos.extender.meta.model.ds.Connect;
import com.kingsoft.dc.khaos.extender.meta.model.ds.RedisConnect;
import com.kingsoft.dc.khaos.extender.meta.utils.RSAEncrypt;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Created by haorenhui on 2019/07/10
 */
public class RedisMetaImpl  extends DmMetaImpl {

    private static Logger logger = LoggerFactory.getLogger(RedisMetaImpl.class);

    @Override
    public Connect decryptDatasourceConnectSecret(String config) {

        RedisConnect connect = JSON.parseObject(config, RedisConnect.class);
        try {
            if(connect.getPassword() != null)
                connect.setPassword(RSAEncrypt.decryptByRSAPassWord(connect.getPassword()));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage(),e);
        }
        return connect;
    }
}
